import { defineStore } from "pinia";
import WebStorageCache from "web-storage-cache";
const cache = new WebStorageCache({
    storage: window.localStorage,
    exp: 1 * 60 * 60 * 24
})


const videoInfoStore = defineStore("videoInfoStore", {
    state() {
        return {
            currentIndex: 0
        }
    },
    actions: {
        setCurrentIndex(index) {
            this.currentIndex = index;
        }
    },
    getters: {

    },
    // 持久化，如果想让这个属性产生使用，必须要加载第三方的持久化插件，我们刚刚在main.js里面已经加载了
    persist: {
        key: "videoInfoStore",
        storage: {
            getItem(key) {
                return cache.get(key);
            },
            setItem(key, value) {
                return cache.set(key, value);
            },
            removeItem(key) {
                return cache.delete(key);
            },
            clear() {
                return cache.clear();
            }
        }
    }
});


export default videoInfoStore;